package com.yupi.springbootinit.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yupi.springbootinit.annotation.AuthCheck;
import com.yupi.springbootinit.common.ErrorCode;
import com.yupi.springbootinit.common.ResultUtils;
import com.yupi.springbootinit.constant.UserConstant;
import com.yupi.springbootinit.exception.BusinessException;
import com.yupi.springbootinit.model.dto.interfaceinfo.InterfaceInfoUpdateRequest;
import com.yupi.springbootinit.model.entity.InterfaceInfo;
import com.yupi.springbootinit.service.InterfaceInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.coyote.OutputBuffer;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("接口信息")
@RestController
@RequestMapping("")
public class InterfaceInfoController {

    @Autowired
    private InterfaceInfoService interfaceInfoService;

//    @ApiOperation("条件分页查询接口信息")
//    @GetMapping("/queryPage/{page}/{limit}")
//    public ResultUtils queryPage(@PathVariable Long page,
//                                 @PathVariable Long limit){
//        Page<InterfaceInfo> resultPage = new Page<>(page, limit);
//        QueryWrapper<InterfaceInfo> queryWrapper = new QueryWrapper<>();
//
//
//    }
//
//    @ApiOperation("根据id查询接口信息")
//    @GetMapping("getInfoById/{id}")
//    public  ResultUtils getInfoById(@PathVariable Long id){
//        InterfaceInfo interfaceInfo = interfaceInfoService.getById(id);
//    }

    @ApiOperation("更新接口信息")
    @PutMapping("putInfo")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public ResultUtils putInfo(@RequestBody InterfaceInfoUpdateRequest interfaceInfo){

        if(interfaceInfo==null||interfaceInfo.getId()<=0){
             throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        InterfaceInfo info = new InterfaceInfo();
        BeanUtils.copyProperties(interfaceInfo,info);

        //参数校验
        interfaceInfoService.validInterfaceInfo(info,false);

//        interfaceInfoService.updateById(interfaceInfo);
        return null;
    }

//    @ApiOperation("保存接口信息")
//    @PostMapping("saveInfo")
//    public ResultUtils saveInfo(@RequestBody InterfaceInfo interfaceInfo){
//        interfaceInfoService.save(interfaceInfo);

//    }



}
